﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;

namespace Tree.Runner
{
    public class GraceAndMercy
    {
        private ManualResetEvent grace;

        private Thread mercy; 

        public GraceAndMercy()
        { 
            grace = new ManualResetEvent(false);
            mercy = new Thread(new ThreadStart(Life));
            mercy.Name = "GraceAndMercyThread";
        }

        public void Hold()
        {
            grace.Reset();
            mercy.Start();
        }

        private void Life()
        {
            while (true)
            {
                grace.WaitOne();
                break;
            }
        }

        public void Release()
        {
            grace.Set();
        }
    }
}
